import java.io.IOException;
import java.net.*;
import java.util.Scanner;

/**
 * @version 1.0
 * @autho 3505
 * @date 2018/5/5
 */
public class TestSend implements Runnable{



    @Override
    public void run() {
        DatagramPacket datagramPacket=null;
        DatagramSocket datagramSocket=null;
        try {
            datagramSocket=new DatagramSocket(9090);
        } catch (SocketException e) {
            e.printStackTrace();
        }
        Scanner scanner=new Scanner(System.in);

        while (true) {
            System.out.println("请输入你要发送的人的ip,多人以英文半角逗号分隔");
            String str1=scanner.nextLine();
            System.out.println("请输入你要发送给"+str1+"的消息：");
            String str2=scanner.nextLine();
            String str=str1+","+str2;
            byte[] by = str.getBytes();
            try {

                datagramPacket = new DatagramPacket(by, 0, by.length, InetAddress.getByName("192.168.36.72"), 9000);
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
//            System.out.println("正在发送数据");
            try {
                datagramSocket.send(datagramPacket);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
